﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using TimApiCallback.Models;

namespace TimApiCallback.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ImCallBackController : ControllerBase
    {

        [HttpPost]
        public IActionResult Post()
        {
            var sss = Request.Query;
            
            var callBackBaseInfo = new CallBackBaseInfo(long.Parse(sss["SdkAppid"]),sss["CallbackCommand"], sss["contenttype"],sss["ClientIP"],sss["OptPlatform"]);
            Console.WriteLine($"callBackBaseInfo:{JsonConvert.SerializeObject(callBackBaseInfo)}");
            var body = Request.Body;
            using (StreamReader streamReader = new StreamReader(body, Encoding.UTF8))
            {
                var result = streamReader.ReadToEnd();
                Console.WriteLine($"body result:{result}");
            }
            //long SdkAppid,string CallbackCommand,string contenttype, string clientIP, string OptPlatform
            return new JsonResult(new
            {
                ActionStatus = "OK",
                ErrorCode = 0,
                ErrorInfo = ""
            });
        }
    }
}